require('dotenv').config();
const express = require('express');
const bodyParser = require('body-parser');
require('body-parser-xml')(bodyParser);
const cors = require('cors');
const router = require('./router');

const app = express();
app.use(express.urlencoded({ limit: '100mb', extended: false }));
app.use(express.json({ limit: '10mb' }));
app.use(bodyParser.xml()); // 解析XML格式为JSON
app.use(cors());
app.use(router);

const commonReplys = require('./dbs/replys-common');
const kepuReplys = require('./dbs/replys-kepu');
const logicReplys = require('./dbs/replys-logic');
const techReplys = require('./dbs/replys-tech');
const scratchFestivalReplys = require('./dbs/replys-scratch-festival');
const scratchGameReplys = require('./dbs/replys-scratch-game');
const scratchMathReplys = require('./dbs/replys-scratch-math');

global.replys = [
  ...commonReplys,
  ...logicReplys,
  ...kepuReplys,
  ...techReplys,
  ...scratchFestivalReplys,
  ...scratchGameReplys,
  ...scratchMathReplys,
];

const port = process.env.PORT || 5000;
app.listen(port, () =>
  console.log(
    `🚀 Wechat-service start success, listening on port ${port} ${process.env.NODE_ENV || 'debug'
    }!`
  )
);
